<html>
<script>
	//回调地狱  --  深层次嵌套问题
	function f1(n){
		return new Promise(function(resolve,reject){
			load(`./data/${n}.json`,function(data){
				document.write(data);
				resolve();
			});
		})
	}
	
	//使用async await
	
	//控制异步先后顺序
	async function  job(n){
		let i = 1;
		while(i<=n){
			await f1(i++);
		}
	}
	
	job(3);
	
	
	//可以使用promise来解决
	function load(url,result){
		let xhr = new XMLHttpRequest();
		xhr.open("GET",url);
		xhr.send();
		xhr.onreadystatechange=function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				let txt = xhr.responseText;
				result(txt);
			}
		}
	}
	
	
	
</script>
</html>